package com.ww.springboot.boot.javabase.proxy.javaInvocation;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 描述：
 *
 * @author wanwei
 * @since 2021-07-08 17:06
 */
public class ManProxy implements InvocationHandler {

    private Person obj;

    private String index;

    public ManProxy(Person obj, String index) {
        this.obj = obj;
        this.index = index;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //ideal debug 每步都会调用tostring方法 需要排除掉
        if (method.getName().equals("toString")) {
            return method.invoke(obj, args);
        }
        System.out.println((index + "proxy before"));
        Object o = method.invoke(obj, args);
        System.out.println((index + "proxy after"));
        return o;
    }
}
